// pages/collegeRecom/collegeRecom.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 输入框控制 
    value:"",
    focus: false,
    inputValue: '',
    // 筛选条件控制
    // 省份
    value1: 0,
    option1: [
      { text: '不限', value: 0 },
      { text: '北京', value: 1 },
      { text: '天津', value: 2 },
      { text: '河北', value: 3 },
      { text: '山西', value: 4 },
      { text: '内蒙古', value: 5 },
      { text: '辽宁', value: 6 },
      { text: '吉林', value: 7 },
      { text: '黑龙江', value: 8 },
      { text: '上海', value: 9 },
      { text: '江苏', value: 10 },
      { text: '浙江', value: 11 },
      { text: '安徽', value: 12 },
      { text: '福建', value: 13 },
      { text: '江西', value: 14 },
      { text: '山东', value: 15 },
      { text: '河南', value: 16 },
      { text: '湖北', value: 17 },
      { text: '广东', value: 18 },
      { text: '广西', value: 19 },
      { text: '海南', value: 20 },
      { text: '重庆', value: 21 },
      { text: '四川', value: 22 },
      { text: '贵州', value: 23 },
      { text: '云南', value: 24 },
      { text: '西藏', value: 25 },
      { text: '陕西', value: 26 },
      { text: '甘肃', value: 27 },
      { text: '青海', value: 28 },
      { text: '宁夏', value: 29 },
      { text: '新疆', value: 30 },
    ],
    value2:0,
    option2:[
      { text: '本科一批', value: 0 },
      { text: '本科二批', value: 1 },
      { text: '高职专科批', value: 2 },
    ],
    value3:0,
    // 类型
    option3: [
      { text: '不限', value: 0 },
      { text: '综合', value: 1 },
      { text: '理工', value: 2 },
      { text: '农业', value: 3 },
      { text: '医药', value: 4 },
      { text: '师范', value: 5 },
      { text: '语言', value: 6 },
      { text: '财经', value: 7 },
      { text: '政法', value: 8 },
      { text: '体育', value: 9 },
      { text: '艺术', value: 10 },
      { text: '民族', value: 11 },
      { text: '军事', value: 12 },
    ],
    // 个人信息
    type:"",
    score:null,
    rank:null,
    // 类型
    rate:1,
    // 结果
    resultList:[],
  },

  onChange(event) {
    this.setData({
      rate:event.detail.index+1,
    });
    wx.request({
      url: 'http://192.168.43.204:9527/willing/recommendUniversity/',
      data:{
        type:this.data.type,
        score:this.data.score,
        province:this.data.option1[this.data.value1].text,
        admissionBatch:this.data.option2[this.data.value2].text,
        category:this.data.option3[this.data.value3].text,
        status:this.data.rate,
      },
      success:(res)=>{
        console.log(res);
        if(this.data.rate == 3){
          let baodiList=[];
          for(let index = 0; index < 50; index++){
            baodiList.push(res.data[index]);
          }
          this.setData({
            resultList:baodiList,
          })
        }else{
          this.setData({
            resultList:res.data,
          })
        }
      }
    })
  },


  changeItem(value){
    this.setData({
      value1 : this.data.option1[value.detail].value,
    });
    wx.request({
      url: 'http://192.168.43.204:9527/willing/recommendUniversity/',
      data:{
        type:this.data.type,
        score:this.data.score,
        province:this.data.option1[this.data.value1].text,
        admissionBatch:this.data.option2[this.data.value2].text,
        category:this.data.option3[this.data.value3].text,
        status:this.data.rate,
      },
      success:(res)=>{
        // console.log(res);
        this.setData({
          resultList:res.data,
        })
      }
    })
  },

  changeItem1(value){
    this.setData({
      value2 : this.data.option2[value.detail].value,
    });
    wx.request({
      url: 'http://192.168.43.204:9527/willing/recommendUniversity/',
      data:{
        type:this.data.type,
        score:this.data.score,
        province:this.data.option1[this.data.value1].text,
        admissionBatch:this.data.option2[this.data.value2].text,
        category:this.data.option3[this.data.value3].text,
        status:this.data.rate,
      },
      success:(res)=>{
        // console.log(res);
        this.setData({
          resultList:res.data,
        })
      }
    })
  },

  changeItem2(value){
    this.setData({
      value3 : this.data.option3[value.detail].value,
    });
    wx.request({
      url: 'http://192.168.43.204:9527/willing/recommendUniversity/',
      data:{
        type:this.data.type,
        score:this.data.score,
        province:this.data.option1[this.data.value1].text,
        admissionBatch:this.data.option2[this.data.value2].text,
        category:this.data.option3[this.data.value3].text,
        status:this.data.rate,
      },
      success:(res)=>{
        // console.log(res);
        this.setData({
          resultList:res.data,
        })
      }
    })
  },

  enterInfo(e){
    let index = e.currentTarget.dataset.index;
    let num = e.currentTarget.dataset.num;
    let dev = e.currentTarget.dataset.dev;
    console.log(dev);
    wx.navigateTo({
      url: '/pages/majorRecom/majorRecom?type=' + this.data.type + '&score=' + this.data.score + '&admissionBatch='+ this.data.option2[this.data.value2].text + "&unvId=" + index + "&num=" + num + "&dev=" + dev,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      type:options.type,
      score:options.score,
      rank:options.rank,
    });
    wx.request({
      url: 'http://192.168.43.204:9527/willing/recommendUniversity/',
      data:{
        type:this.data.type,
        score:this.data.score,
        province:this.data.option1[this.data.value1].text,
        admissionBatch:this.data.option2[this.data.value2].text,
        category:this.data.option3[this.data.value3].text,
        status:this.data.rate,
      },
      success:(res)=>{
        // console.log(res);
        this.setData({
          resultList:res.data,
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})